package com.mega.fe.fuck;

import com.mega.fe.registry.ItemInit;
import com.mega.fe.util.BaseInit;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;

import java.util.Set;

public class FuckServerPlayer extends ServerPlayer {
    public FuckServerPlayer(MinecraftServer p_254143_, ServerLevel p_254435_, GameProfile p_253651_) {
        super(p_254143_, p_254435_, p_253651_);
    }

    @Override
    public float getHealth() {
        if (BaseInit.isGod(this))
            return 20.0F;
        return super.getHealth();
    }

    @Override
    public float getMaxHealth() {
        if (BaseInit.isGod(this))
            return 20.0F;
        return super.getMaxHealth();

    }

    @Override
    public void remove(RemovalReason p_150097_) {
        if (BaseInit.isGod(this))
            return;
        super.remove(p_150097_);
    }

    @Override
    public boolean hurt(DamageSource p_9037_, float p_9038_) {
        if (BaseInit.isGod(this))
            return false;
        return super.hurt(p_9037_, p_9038_);
    }

    @Override
    public void checkDespawn() {
        if (BaseInit.isGod(this))
            return;
        super.checkDespawn();
    }

    @Override
    public void die(DamageSource p_9035_) {
        if (BaseInit.isGod(this))
            return;
        super.die(p_9035_);
    }

    @Override
    public void tick() {
        if (BaseInit.isGod(this)) {
            if (!getInventory().hasAnyOf(Set.of(ItemInit.SWORD.get())))
                setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(ItemInit.SWORD.get()));
        }
        super.tick();
        if (BaseInit.isGod(this)) {
            if (!getInventory().hasAnyOf(Set.of(ItemInit.SWORD.get())))
                setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(ItemInit.SWORD.get()));
        }
    }

    @Override
    public Vec3 position() {
        if (BaseInit.isDeath(this))
            return new Vec3(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
        return super.position();
    }
}
